package com.system.manager.modules.risk.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.PageDTO;
import com.system.manager.common.entity.Result;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.risk.dto.FileStationVo;
import com.system.manager.modules.risk.dto.RiskRiskVo;
import com.system.manager.modules.risk.entity.TbFile;
import com.system.manager.modules.risk.entity.TbFileStation;
import com.system.manager.modules.risk.service.ITbFileService;
import com.system.manager.modules.risk.service.ITbFileStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-11-23
 */
@Slf4j
@Api(tags = "文件和部门的中间表")
@RestController
@RequestMapping("/risk/tb-file-station/")
public class TbFileStationController {

    @Autowired
    private ITbFileStationService iTbFileStationService;

    @ApiOperation("查看所有文件")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @GetMapping("list")
    public Result riskFileStation() {

        // 获取所有的风险类型
        List<TbFileStation> list = iTbFileStationService.list();

        return Result.ok(list);
    }

    @ApiOperation("添加文件给部门")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @PostMapping("addFileStation")
    public Result addFileStation(@RequestBody FileStationVo fileStationVo) {
        iTbFileStationService.insertFileStation(fileStationVo);
        return Result.ok();
    }
    @ApiOperation("根据部门查找所有的文件")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @PostMapping("findFileByStationId")
    public Result findFileByStationId(Integer stationId) {
        List<Integer> integers = iTbFileStationService.selectByStationId(stationId);
        return Result.ok(integers,integers.size());
    }
}
